import requests
def get_token(domain_name, user_name, user_passwd, ap):
    uri = f'https://iam.{ap}.myhuaweicloud.com/v3/auth/tokens'
    req_body = {
        "auth": {
            "identity": {
                "methods": [
                    "password"
                ],
                "password": {
                    "user": {
                        "domain": {
                            "name": domain_name
                        },
                        "name": user_name,
                        "password": user_passwd
                    }
                }
            }
        }
        ,
        "scope": {
            # "domain": {
            #     "name": domain_name
            # }
            "project": {
                "id": "08c223de210010642fe3c0141fa306e5"
                # "name": "ap-southeast-1"
            }
        }
    }

    res = requests.post(uri, json=req_body)
    return res.headers['X-Subject-Token']

AP = 'ap-southeast-1'
PROJECT_ID = '08c223de210010642fe3c0141fa306e5'  # ap-southeast-1 Hong Kong
ENDPOINT = f'iam.{AP}.myhuaweicloud.com'
DOMAIN_NAME = 'hwstaff_juzhen'
USER_NAME = 'hwstaff_juzhen'
USER_PASSWD = 'my_password!'

token = get_token(domain_name=DOMAIN_NAME, user_name=USER_NAME, user_passwd=USER_PASSWD, ap=AP)

uri = f'https://vpc.ap-southeast-1.myhuaweicloud.com/v3/{PROJECT_ID}/vpc/vpcs'
headers = {
    'X-Auth-Token': token
}
res = requests.get(uri, headers=headers)
print('got res', res)
print(res.json())
print(res.headers)
